package com.lk.mall.controller.mall;

import com.lk.mall.common.IndexConfigTypeEnum;
import com.lk.mall.common.SystemConstant;
import com.lk.mall.model.vo.IndexInfoVo;
import com.lk.mall.model.vo.MallCarouselVo;
import com.lk.mall.model.vo.MallIndexConfigGoodsVo;
import com.lk.mall.service.ICarouselService;
import com.lk.mall.service.IIndexConfigService;
import com.lk.mall.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lak
 * @since 2022-08-31
 */
@RestController
@Api(tags = "1.新蜂商城首页接口")
@RequestMapping("/api/v1")
public class IndexConfigController {

    @Autowired
    private IIndexConfigService indexConfigService;

    @Autowired
    private ICarouselService carouselService;
    /*
    获取首页信息
     */
    @GetMapping("index-infos")
    @ApiOperation(value = "获取首页数据", notes = "轮播图、新品、推荐等")
    private R<IndexInfoVo> getIndexInfo() {

        IndexInfoVo indexInfoVo = new IndexInfoVo();

        //(1)获取轮播图信息———自己写
/*        List<Carousel> carouselList = carouselService.list(null);
        List<MallCarouselVo> carouselVoList = new ArrayList<>();
        for (Carousel carousel : carouselList) {
            MallCarouselVo carouselVo = new MallCarouselVo();
            BeanUtils.copyProperties(carousel,carouselVo);
            carouselVoList.add(carouselVo);
        }*/
        //改造
        List<MallCarouselVo> carouselVoList= carouselService.getCarousels(SystemConstant.INDEX_CAROUSEL_NUMBER);
        //(2)获取热门商品信息
        List<MallIndexConfigGoodsVo> hotGoods=indexConfigService.getIndexGoods(IndexConfigTypeEnum.INDEX_GOODS_HOT.getType(),SystemConstant.INDEX_GOODS_HOT_NUMBER);
        //(2)获取新品商品信息
        List<MallIndexConfigGoodsVo> newGoods=indexConfigService.getIndexGoods(IndexConfigTypeEnum.INDEX_GOODS_NEW.getType(),SystemConstant.INDEX_GOODS_NEW_NUMBER);
        //获取推荐商品信息
        List<MallIndexConfigGoodsVo> recommondGoods=indexConfigService.getIndexGoods(IndexConfigTypeEnum.INDEX_GOODS_RECOMMEND.getType(),SystemConstant.INDEX_GOODS_RECOMMOND_NUMBER);

        indexInfoVo.setCarousels(carouselVoList);
        indexInfoVo.setHotGoodses(hotGoods);
        indexInfoVo.setNewGoodses(newGoods);
        indexInfoVo.setRecommendGoodses(recommondGoods);

        return  new R<IndexInfoVo>().ok(indexInfoVo);
    }
}

